/*
 * Toedo
 * Copyright (C) 2009-2010 J. Devauchelle and contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 3 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

package org.toedo.utils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.toedo.controllers.Controller;
import org.toedo.preferences.PreferenceConstants;

public class DateUtils {
	
	/**
	 * Convert a Date to its string representation in the format specified by the user.
	 * @param date The Date to convert.
	 * @return The string representation of the date in the format specified by the user.
	 */
	public static String dateToDisplayString(Date date) {
		DateFormat dateFormat = new SimpleDateFormat(Controller.getInstance().getPreferenceStore().getString(PreferenceConstants.DISPLAY_DATE_FORMAT));
		return dateFormat.format(date); // + " " + timeFormat.format(date); //$NON-NLS-1$
	}
	
	public static String dateTimeToDisplayString(Date date) {
		DateFormat dateFormat = new SimpleDateFormat(Controller.getInstance().getPreferenceStore().getString(PreferenceConstants.DISPLAY_DATE_FORMAT));
		DateFormat timeFormat = new SimpleDateFormat(Controller.getInstance().getPreferenceStore().getString(PreferenceConstants.DISPLAY_TIME_FORMAT));
		return dateFormat.format(date) + " " + timeFormat.format(date); //$NON-NLS-1$
	}

}
